﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DevAwesome.WebDataBridge {
    public class Bridge : List<EndPoint> {

        public EndPoint this[ string endPointName ] {
            get {
                var query = this.Where( x => x.EndPointName == endPointName.ToLower( ) );
                return HasEndPoint( endPointName.ToLower( ) ) ? query.First( ) : null;
            }
            set {
                if( !HasEndPoint( endPointName.ToLower( ) ) )
                    this.Add( value );
                else
                    this[ endPointName.ToLower( ) ] = value;
            }
        }

        public string BridgeId { get; set; }

        public Bridge( string bridgeId ) {
            this.BridgeId = bridgeId.ToLower( );
        }

        public bool HasEndPoint( string endPoint ) {
            return this.Where( x => x.EndPointName == endPoint.ToLower( ) ).Count( ) > 0;
        }

    }

}
